#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

template<typename T=int>
inline T read() {
    T x;
    cin >> x;
    return x;
}

const int MOD = 1000;//
int quick_power(int a, int n) {   //快速幂算法 计算 a^n% MOD
    if (a == 1 || n == 0)return 1;
    if (a == 0 || n == 1)return a % MOD;
    int t = quick_power(a, n / 2);
    return t * t % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << quick_power(3, 1997) << endl;
    return 0;
}
